<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!-- 车型选择 -->
<script type="text/javascript">

//修改日志：贷款模式初始化设置了为空，签约每月还款额----实际贷款额设置了d5
function initBankRate(bankRate, fn){
	var loanBank = $('#loanBank').val();
	var loanMonth = $('#loanMonth').val();
	if(loanBank == '' || loanMonth == '') {
		$('#bankRate').html('<option value="" selected="selected">请先选择银行和贷款期限</option>');
		return;
	}
	$.dpAjax({
		show:false,
		url:'${basePath}/OtherBankRateController/listSelect',
		data:{ "loanBank":loanBank,"loanMonth": loanMonth},
		success: function(datas){
			var result = datas.result.rows;
			var html = '<option value="" selected="selected">请选择...</option>';
			if(result && result.length && result.length > 0) {
			      for(var i = 0;i < result.length; i++){
			          var record = result[i];
			          var bankRate_ = showNumber(record.bankRate ? (record.bankRate * 100) : 0, 4);
			          html += '<option value="' + bankRate_ + '">' + bankRate_ + '% </option>';
			          /* html += '<option value="' + bankRate_ + '">' + record.bankCodeDisplay + '(' + bankRate_ + '%)</option>'; */
			      }
			 }
			$("#bankRate").html(html);
			$("#bankRate").val('');
			if(fn) {
				fn(bankRate);
			}
      }
	});
}


//征信查询银行
var queryBankCode;
//初始化贷款银行和贷款模式
function initLoanBankAndType(){
	//银行初始化
	if(queryBankCode && queryBankCode != ''){
		$('#loanBank').val(queryBankCode);
	} else {
		$('#loanBank').val('ICBC');
	}
	showLoan();
	//贷款模式初始化
	var loanBank = $('#loanBank').val();
	if(loanBank == 'ICBC') {
		$('#loanType').val("");
	} else if(loanBank == 'BOC'){
		$('#loanType').val("");
	}else if(loanBank == 'TJICBC'){
		$('#loanType').val("");
	}
	showType();
}

function showLoanData(ywBusinessLoan) {
	var bankRate_ = showNumber(ywBusinessLoan.bankRate ? ywBusinessLoan.bankRate * 100 : 0, 4);
	$('#fast_bankRate').val(bankRate_);
	
	$('#loanId').val(ywBusinessLoan.replaceId);
	if(ywBusinessLoan.loanBank && ywBusinessLoan.loanBank != '') {
		$('#loanBank').val(ywBusinessLoan.loanBank);
	}
	showLoan();
	$('#loanType').val(ywBusinessLoan.loanType);
	showType();
	var price = $('#price').val();
	$('#carPrice').val(!price || price == '' ? showNumber(ywBusinessLoan.carPrice) : price);
	$('#carEstimatePrice').val(showNumber(ywBusinessLoan.carEstimatePrice));
	$('#carAge').val(ywBusinessLoan.carAge);
	$('#loanMonth').val(ywBusinessLoan.loanMonth);
	
	var bankRate = $('#fast_bankRate').val();
	initBankRate(bankRate, function(bankRate){
		$('#bankRate').val(bankRate);
	});
	
	$('#loanAmount').val(showNumber(ywBusinessLoan.loanAmount));
	$('#companyRate').val(showNumber(ywBusinessLoan.companyRate ? ywBusinessLoan.companyRate * 100 : 0, 4));
	$('#ccol2').val(showNumber((ywBusinessLoan.ccol2 && ywBusinessLoan.ccol2 != '')? parseFloat(ywBusinessLoan.ccol2) * 100 : 0, 4));
	$('#servicePrice').val(showNumber(ywBusinessLoan.servicePrice));
	$('#ccol1').val(ywBusinessLoan.ccol1);
	
	//结果字段
	$('#signLoanAmount').val(showNumber(ywBusinessLoan.signLoanAmount));
	$('#totalRepaymentAmount').val(showNumber(ywBusinessLoan.totalRepaymentAmount));
	$('#bankRateAmount').val(showNumber(ywBusinessLoan.bankRateAmount));
	$('.amountMonthly').val(showNumber(ywBusinessLoan.amountMonthly));
    $('#zhkcj').val(showNumber(ywBusinessLoan.zhkcj * 100, 4));
    $('#qyhkcj').val(showNumber(ywBusinessLoan.qyhkcj * 100, 4));
    warning();
	$('#firstMonthTotalAmount').val(showNumber(ywBusinessLoan.firstMonthTotalAmount));
	$('#monthlyPrincipalAmount').val(showNumber(ywBusinessLoan.monthlyPrincipalAmount));
	$('#firstMonthAmount').val(showNumber(ywBusinessLoan.firstMonthAmount));
	$('#monthlyFee').val(showNumber(ywBusinessLoan.monthlyFee));
	$('#firstMonthFee').val(showNumber(ywBusinessLoan.firstMonthFee));
	$('#monthlyFee2').val(showNumber(ywBusinessLoan.monthlyFee2));
	$('#firstMonthFee2').val(showNumber(ywBusinessLoan.firstMonthFee2));
	$('#stagesFee').val(showNumber(ywBusinessLoan.stagesFee));
	$('#stagesFee2').val(showNumber(ywBusinessLoan.stagesFee2));
	$('#sfbl').val(showNumber(ywBusinessLoan.sfbl *100));
	$('#firstPaymentAmount').val(showNumber(ywBusinessLoan.firstPaymentAmount));
	
	$('#trialAssureRate').val(showNumber(ywBusinessLoan.trialAssureRate ? ywBusinessLoan.trialAssureRate * 100 : 0, 4));
	$('#assureAmount').val(showNumber(ywBusinessLoan.assureAmount));
	$('#stageAmount').val(showNumber(ywBusinessLoan.stageAmount));
	$('#fqbl').val(showNumber(ywBusinessLoan.fqbl ? ywBusinessLoan.fqbl * 100 : 0, 4));
	$('#signFirstPaymentAmount').val(showNumber(ywBusinessLoan.signFirstPaymentAmount));
	
	changePrice();
	
}

function showLoanDataB(ywBusinessLoan) {
	var bankRate_ = showNumber(ywBusinessLoan.bankRate ? ywBusinessLoan.bankRate * 100 : 0, 4); 
	$('#fast_bankRate').val(bankRate_);
	
	$('#loanId').val(ywBusinessLoan.replaceId);
  	if(ywBusinessLoan.loanBank && ywBusinessLoan.loanBank != '') {
  		$('#loanBank').val(ywBusinessLoan.loanBank);
  	}
	showLoan();
	$('#loanType').val(ywBusinessLoan.loanType);
	showType();
	var price = $('#price').val();
	$('#carPrice').val(!price || price == '' ? showNumber(ywBusinessLoan.carPrice) : price);
	$('#carEstimatePrice').val(showNumber(ywBusinessLoan.carEstimatePrice));
	$('#carAge').val(ywBusinessLoan.carAge);
	$('#loanMonth').val(ywBusinessLoan.loanMonth);
	
	$('#loanAmount').val(showNumber(ywBusinessLoan.loanAmount));
	$('#companyRate').val(showNumber(ywBusinessLoan.companyRate ? ywBusinessLoan.companyRate * 100 : 0, 4));
	$('#ccol2').val(showNumber((ywBusinessLoan.ccol2 && ywBusinessLoan.ccol2 != '')? parseFloat(ywBusinessLoan.ccol2) * 100 : 0, 4));
	$('#servicePrice').val(showNumber(ywBusinessLoan.servicePrice));
	$('#ccol1').val(ywBusinessLoan.ccol1);
	
	//结果字段
	$('#signLoanAmount').val(showNumber(ywBusinessLoan.signLoanAmount));
	$('#totalRepaymentAmount').val(showNumber(ywBusinessLoan.totalRepaymentAmount));
	$('#bankRateAmount').val(showNumber(ywBusinessLoan.bankRateAmount));
	$('.amountMonthly').val(showNumber(ywBusinessLoan.amountMonthly));
    $('#zhkcj').val(showNumber(ywBusinessLoan.zhkcj * 100, 4));
    $('#qyhkcj').val(showNumber(ywBusinessLoan.qyhkcj * 100, 4));
    warning();
	$('#firstMonthTotalAmount').val(showNumber(ywBusinessLoan.firstMonthTotalAmount));
	$('#monthlyPrincipalAmount').val(showNumber(ywBusinessLoan.monthlyPrincipalAmount));
	$('#firstMonthAmount').val(showNumber(ywBusinessLoan.firstMonthAmount));
	$('#monthlyFee').val(showNumber(ywBusinessLoan.monthlyFee));
	$('#firstMonthFee').val(showNumber(ywBusinessLoan.firstMonthFee));
	$('#monthlyFee2').val(showNumber(ywBusinessLoan.monthlyFee2));
	$('#firstMonthFee2').val(showNumber(ywBusinessLoan.firstMonthFee2));
	$('#stagesFee').val(showNumber(ywBusinessLoan.stagesFee));
	$('#stagesFee2').val(showNumber(ywBusinessLoan.stagesFee2));
	$('#sfbl').val(showNumber(ywBusinessLoan.sfbl *100));
	$('#firstPaymentAmount').val(showNumber(ywBusinessLoan.carPrice - ywBusinessLoan.loanAmount ));
	//modify by zzj
	$('#trialAssureRate').val(showNumber(ywBusinessLoan.trialAssureRate ? ywBusinessLoan.trialAssureRate * 100 : 0, 4));
	$('#assureAmount').val(showNumber(ywBusinessLoan.assureAmount));
	$('#stageAmount').val(showNumber(ywBusinessLoan.stageAmount));
	$('#fqbl').val(showNumber(ywBusinessLoan.fqbl ? ywBusinessLoan.fqbl * 100 : 0, 4));
	$('#signFirstPaymentAmount').val(showNumber(ywBusinessLoan.signFirstPaymentAmount));
}

//计算并保存贷款信息
function saveLoan(callback){
	saveLoanAction(callback);
}
/* var counta=function(){
	  var signLoanAmountOld=$("#signLoanAmountOld").val()==""?"0":$("#signLoanAmountOld").val();
	  var signLoanAmountNew=$("#signLoanAmountNew").val()==""?"0":$("#signLoanAmountNew").val();
	  $("#signLoanAmountAdjust").val((parseFloat(signLoanAmountNew)-parseFloat(signLoanAmountOld)).toFixed(2));
  }
var countb=function(){
	  var loanAmountOld=$("#loanAmountOld").val()==""?"0":$("#loanAmountOld").val();
	  var loanAmountNew=$("#loanAmountNew").val()==""?"0":$("#loanAmountNew").val();
	  $("#loanAmountAdjust").val((parseFloat(loanAmountNew)-parseFloat(loanAmountOld)).toFixed(2));
}
var countc=function(){
	  var rebateDealerOld=$("#rebateDealerOld").val()==""?"0":$("#rebateDealerOld").val();
	  var rebateDealerNew=$("#rebateDealerNew").val()==""?"0":$("#rebateDealerNew").val();
	  $("#rebateDealerAdjust").val((parseFloat(rebateDealerNew)-parseFloat(rebateDealerOld)).toFixed(2));
}
var countd=function(){
	  var rebateProvinceOld=$("#rebateProvinceOld").val()==""?"0":$("#rebateProvinceOld").val();
	  var rebateProvinceNew=$("#rebateProvinceNew").val()==""?"0":$("#rebateProvinceNew").val();
	  $("#rebateProvinceAdjust").val((parseFloat(rebateProvinceNew)-parseFloat(rebateProvinceOld)).toFixed(2));
}
var counte=function(){
	  var rebateAreaOld=$("#rebateAreaOld").val()==""?"0":$("#rebateAreaOld").val();
	  var rebateAreaNew=$("#rebateAreaNew").val()==""?"0":$("#rebateAreaNew").val();
	  $("#rebateAreaAdjust").val((parseFloat(rebateAreaNew)-parseFloat(rebateAreaOld)).toFixed(2));
} */
//垫款调整B专用方法
function saveLoanB(){
	var carType = $('#carType').val();
	var loanMonth = $('#loanMonth').val();
	var carAge  = $('#carAge').val();
	if(carType == '02') { //二手车
		var continuedMonths = countContinuedMonths();
		if(continuedMonths > 120) {
			layer.msg('不符合贷款要求，建议调整贷款期', {icon: 5});
			return;
		}
	}
	
	var validstatus = $("#commentFormd").valid();
	if(!validstatus){
		layer.msg("有验证未通过，请仔细检查！",{icon:7});
		return;
	}
	
	var data = {};
	var id = $('#loanId').val();
	data.busiId = $("#busiId").val();
	data.cusId = $("#customerId").val();
// 	data.carId = carId;
	data.carType = $('#carType').val();
	//输入字段
	data.loanBank = $('#loanBank').val();
	data.loanType = $('#loanType').val();
	data.carPrice = $('#carPrice').val();
	data.carEstimatePrice = $('#carEstimatePrice').val();
	data.carAge = $('#carAge').val();
	data.loanMonth = $('#loanMonth').val();
	data.bankRate = $('#bankRate').val() / 100;
	data.loanAmount = $('#loanAmount').val();
	data.servicePrice = $('#servicePrice').val();
	data.ccol2 = $('#ccol2').val() / 100;
	
	//结果字段
	data.signLoanAmount = $('#signLoanAmount').val();
	data.totalRepaymentAmount = $('#totalRepaymentAmount').val();
	data.amountMonthly = $('.amountMonthly').val();
	data.firstMonthTotalAmount = $('#firstMonthTotalAmount').val();
	data.monthlyPrincipalAmount = $('#monthlyPrincipalAmount').val();
	data.firstMonthAmount = $('#firstMonthAmount').val();
	data.monthlyFee = $('#monthlyFee').val();
	data.firstMonthFee = $('#firstMonthFee').val();
	data.monthlyFee2 = $('#monthlyFee2').val();
	data.firstMonthFee2 = $('#firstMonthFee2').val();
	data.stagesFee = $('#stagesFee').val();
	data.stagesFee2 = $('#stagesFee2').val();
	data.firstPaymentAmount = $("#firstPaymentAmount").val();
	data.ccol1 = $('#ccol1').val();
	
	data.trialAssureRate = $('#trialAssureRate').val() / 100;
	data.assureAmount = $('#assureAmount').val();
	data.stageAmount = $('#stageAmount').val();
	data.fqbl = $('#fqbl').val() / 100;
	data.signFirstPaymentAmount = $('#signFirstPaymentAmount').val();
	
	$.dpAjax({
 		url:'${basePath}/YwBusinessLoanController/saveWithOut',
		data:data,
		success: function(datas){
				layer.msg('车贷计算成功，请注意保存当前车辆信息', {icon: 6,time:4000});
				var record = datas.result;
				$('#loanId').val(record.replaceId);
				//结果字段
				$('#signLoanAmount').val(showNumber(record.signLoanAmount));
				$('#signLoanAmountNew').val(showNumber(record.signLoanAmount));
				$('#loanAmountNew').val(showNumber(record.loanAmount));
				$('#totalRepaymentAmount').val(showNumber(record.totalRepaymentAmount));
				$('#bankRateAmount').val(showNumber(record.bankRateAmount));
				$('.amountMonthly').val(showNumber(record.amountMonthly));
				$('#zhkcj').val(showNumber(record.zhkcj * 100));
				$('#qyhkcj').val(showNumber(record.qyhkcj * 100));
				warning();
				$('#companyRate').val(showNumber(record.companyRate ? record.companyRate * 100 : 0, 4));
				$('#firstMonthTotalAmount').val(showNumber(record.firstMonthTotalAmount));
				$('#monthlyPrincipalAmount').val(showNumber(record.monthlyPrincipalAmount));
				$('#firstMonthAmount').val(showNumber(record.firstMonthAmount));
				$('#monthlyFee').val(showNumber(record.monthlyFee));
				$('#firstMonthFee').val(showNumber(record.firstMonthFee));
				$('#monthlyFee2').val(showNumber(record.monthlyFee2));
				$('#firstMonthFee2').val(showNumber(record.firstMonthFee2));
				$('#stagesFee').val(showNumber(record.stagesFee));
				$('#stagesFee2').val(showNumber(record.stagesFee2));
				$('#servicePrice').val(showNumber(record.servicePrice));
				
				$('#trialAssureRate').val(showNumber(record.trialAssureRate ? record.trialAssureRate * 100 : 0, 4));
				$('#assureAmount').val(showNumber(record.assureAmount));
				$('#stageAmount').val(showNumber(record.stageAmount));
				$('#fqbl').val(showNumber(record.fqbl ? record.fqbl * 100 : 0, 4));
				$('#signFirstPaymentAmount').val(showNumber(record.signFirstPaymentAmount));
				//$('#firstPaymentAmount').val(showNumber(ywBusinessLoan.carPrice - ywBusinessLoan.loanAmount ));
				counta();
				countb();
				countc();
				countd();
				counte();
		}
	});
}
function saveLoanAction(callback){
	var carId = $('#carId').val();
	if(!carId || carId == ''){
		layer.msg('请先保存车辆信息!', {icon: 5});
		return;
	}
	var carType = $('#carType').val();
	var loanMonth = $('#loanMonth').val();
	var carAge  = $('#carAge').val();
	if(carType == '02') { //二手车
		var continuedMonths = countContinuedMonths();
		if(continuedMonths > 120) {
			layer.msg('不符合贷款要求，建议调整贷款期', {icon: 5});
			return;
		}
	}
	
	var validstatus = $("#commentFormd").valid();
	if(!validstatus){
		layer.msg("有验证未通过，请仔细检查！",{icon:7});
		return;
	}
	
	var data = {};
	var id = $('#loanId').val();
	data.busiId = $("#busiId").val();
	data.cusId = $("#customerId").val();
	data.carId = carId;
	data.carType = $('#carType').val();
	//输入字段
	data.loanBank = $('#loanBank').val();
	data.loanType = $('#loanType').val();
	data.carPrice = $('#carPrice').val();
	data.carEstimatePrice = $('#carEstimatePrice').val();
	data.carAge = carAge;
	data.loanMonth = $('#loanMonth').val();
	data.bankRate = $('#bankRate').val() / 100;
	data.loanAmount = $('#loanAmount').val();
	data.servicePrice = $('#servicePrice').val();
	/* data.companyRate = $('#companyRate').val() / 100; */
	data.ccol2 = $('#ccol2').val() / 100;
	
	//结果字段
	data.signLoanAmount = $('#signLoanAmount').val();
	data.totalRepaymentAmount = $('#totalRepaymentAmount').val();
	data.amountMonthly = $('.amountMonthly').val();
	data.firstMonthTotalAmount = $('#firstMonthTotalAmount').val();
	data.monthlyPrincipalAmount = $('#monthlyPrincipalAmount').val();
	data.firstMonthAmount = $('#firstMonthAmount').val();
	data.monthlyFee = $('#monthlyFee').val();
	data.firstMonthFee = $('#firstMonthFee').val();
	data.monthlyFee2 = $('#monthlyFee2').val();
	data.firstMonthFee2 = $('#firstMonthFee2').val();
	data.stagesFee = $('#stagesFee').val();
	data.stagesFee2 = $('#stagesFee2').val();
	data.ccol1 = $('#ccol1').val();
	
	data.trialAssureRate = $('#trialAssureRate').val() / 100;
	data.assureAmount = $('#assureAmount').val();
	data.stageAmount = $('#stageAmount').val();
	data.fqbl = $('#fqbl').val() / 100;
	data.signFirstPaymentAmount = $('#signFirstPaymentAmount').val();
	
	if(id && id != '') {
		data.id= id;
		url = '${basePath}/YwBusinessLoanController/modify';
	} else {
		url = '${basePath}/YwBusinessLoanController/save';
	}
	$.dpAjax({
 		url:url,
		data:data,
		success: function(datas){
				layer.msg('车贷计算成功，请注意保存当前车辆信息', {icon: 6,time:4000});
				var record = datas.result;
				$('#loanId').val(record.replaceId);
				//结果字段
				$('#signLoanAmount').val(showNumber(record.signLoanAmount));
				$('#totalRepaymentAmount').val(showNumber(record.totalRepaymentAmount));
				$('#bankRateAmount').val(showNumber(record.bankRateAmount));
				$('.amountMonthly').val(showNumber(record.amountMonthly));
				$('#zhkcj').val(showNumber(record.zhkcj * 100));
				$('#qyhkcj').val(showNumber(record.qyhkcj * 100));
				warning();
				$('#companyRate').val(showNumber(record.companyRate ? record.companyRate * 100 : 0, 4));
				$('#firstMonthTotalAmount').val(showNumber(record.firstMonthTotalAmount));
				$('#monthlyPrincipalAmount').val(showNumber(record.monthlyPrincipalAmount));
				$('#firstMonthAmount').val(showNumber(record.firstMonthAmount));
				$('#monthlyFee').val(showNumber(record.monthlyFee));
				$('#firstMonthFee').val(showNumber(record.firstMonthFee));
				$('#monthlyFee2').val(showNumber(record.monthlyFee2));
				$('#firstMonthFee2').val(showNumber(record.firstMonthFee2));
				$('#stagesFee').val(showNumber(record.stagesFee));
				$('#stagesFee2').val(showNumber(record.stagesFee2));
				$('#servicePrice').val(showNumber(record.servicePrice));
				$('#firstPaymentAmount').val(showNumber(record.firstPaymentAmount));
				$('#sfbl').val(showNumber(record.sfbl *100 ));
				
				$('#trialAssureRate').val(showNumber(record.trialAssureRate ? record.trialAssureRate * 100 : 0, 4));
				$('#assureAmount').val(showNumber(record.assureAmount));
				$('#stageAmount').val(showNumber(record.stageAmount));
				$('#fqbl').val(showNumber(record.fqbl ? record.fqbl * 100 : 0, 4));
				$('#signFirstPaymentAmount').val(showNumber(record.signFirstPaymentAmount));
				if(callback) {
					callback();
				}
		}
	});
}

/* 价格 */
function changePrice(){
	var price = $('#price').val();
	$('#carPrice').val(price);
}

var onDkBank = function() {	
	countLoanMonth();
	showLoan();
	showType();
	clearOut();
	
	var bankRate = $('#fast_bankRate').val();
	initBankRate(bankRate, function(bankRate){
		$('#bankRate').val(bankRate);
	});
}

var dkPattern = function(){
	showType();
	clearOut();
}

//显影选项卡
function showLoan(){
	var loanBank = $('#loanBank').val();
	if(loanBank == 'ICBC') {
		$('.bank2').hide();
		$('.bank1').show();
		$('#loanType').val('04');
	} else if(loanBank == 'BOC') {
		$('.bank1').hide();
		$('.bank2').show();
		$('#loanType').val('05');
	}else if(loanBank == 'TJICBC') {
		$('.bank2').hide();
		$('.bank1').show();
		$('#loanType').val('04');
	}
}

function showType(){
	var loanBank = $('#loanBank').val(); //银行模式
	var loanType = $('#loanType').val();
	if(loanType == "") {//空选择 //签约每月还款额----实际贷款额设置了d5
		$('.d3, .d1, .d2, .d5, .Tjicbc').hide();
	}else if(loanBank == "ICBC" && loanType == "04"){  //杭州工商平息
		$('.d3, .d2, .Tjicbc').hide();
		$('.d1, .d5').show();
		$('.dtj').hide();
		$(".shisuanlilv").text("试算公司利率(%)：");
		$("#signLoanAmount").attr('readonly','readonly');
		$('#servicePrice').attr('required','required');
		$('#servicePrice').removeAttr('readonly');
		$('#ccol2').removeAttr('required');
	} else if(loanBank == "ICBC" && loanType == "02"){//杭州工商高息
		$('.d1, .d3, .Tjicbc').hide();
		$('.d2, .d5').show();
		$('.dtj').hide();
		$(".shisuanlilv").text("试算公司利率(%)：");
		$("#signLoanAmount").attr('readonly','readonly');
		$('#servicePrice').removeAttr('required');
		$('#servicePrice').attr('readonly','readonly');
		$('#ccol2').attr('required','required');
	}else if(loanBank == "TJICBC" && loanType == "04"){  //天津工商平息
		$('.d3, .d2').hide();
		$('.d1, .d5, .Tjicbc, .d6').show();
		$('.dtj').show();
		$(".shisuanlilv").text("合计费率(%)：");
		$('#servicePrice').attr('readonly','readonly');
		$('#trialAssureRate').attr('readonly','readonly');
		$('#trialAssureRate').removeAttr('required');
		$('#servicePrice').attr('required','required');
		$('#servicePrice').removeAttr('readonly');
		$('#ccol2').removeAttr('required');
	} else if(loanBank == "TJICBC" && loanType == "02"){//天津工商高息
		$('.d1, .d3').hide();
		$('.d2, .d5, .Tjicbc').show();
		$('.TjicbcHide').hide();
		$('.dtj').show();
		$(".shisuanlilv").text("合计费率(%)：");
		$('#servicePrice').attr('readonly','readonly');
		$('#servicePrice').removeAttr('required','required');
		$("#signLoanAmount").attr('readonly');
		$("#signLoanAmount").removeAttr('required','required');
		$('#ccol2').attr('required','required');
	} else if(loanType == "05"){//中国银行
		$('.d1, .d2, .Tjicbc').hide();
		$('.d3, .d5').show();
		$('.dtj').hide();
		$(".shisuanlilv").text("试算公司利率(%)：");
		$('#servicePrice').removeAttr('required');
		$('#ccol2').attr('required','required');
	}
}

function clearOut() {
	$('#servicePrice').val('');
	$('#signLoanAmount').val('');
	$('#bankRateAmount').val('');
	$('#totalRepaymentAmount').val('');
	$('#amountMonthly').val('');
	$('#firstMonthTotalAmount').val('');
	$('#zhkcj').val('');
	$('#qyhkcj').val('');
	$('#zhkcj_show').hide();
	$('#qyhkcj_show').hide();
	$('#monthlyPrincipalAmount').val('');
	$('#firstMonthAmount').val('');
	$('#monthlyFee').val('');
	$('#firstMonthFee').val('');
	$('#monthlyFee2').val('');
	$('#firstMonthFee2').val('');
	$('#stagesFee').val('');
	$('#stagesFee2').val('');
	$('#trialAssureRate').val('0.00');
	$('#assureAmount').val('0.00');
	$('#stageAmount').val('');
	$('#fqbl').val('');
	$('#signFirstPaymentAmount').val('');
}

/**
 * 计算贷款模式
 */
function countLoanMonth(obj){
	obj = obj || $('#startDate').val();
	if(obj && obj != '') {
		$('#startDate').val(obj.replace(/[^\.\d]/g,''));
		$('#startDate').val(obj.replace('.',''));
		
		var startYear = formateToYear(obj);
		$('#startYear').val(startYear);
		var startMonth = getMonth(obj);
		$('#startMonth').val(startMonth);
		
		var now = laydate.now();
		var nowYear = formateToYear(now);
		var nowMonth = getMonth(now);
		
		$('#carAge').val((nowYear - startYear) * 12 + (nowMonth - startMonth));
	}
	
	continuedMonthsWarning();
	
	/* 不限制，都显示 */
	/* if($("#carType").val() == '02') { //二手车
		var startYear = $('#startYear').val();
		var startMonth = $('#startMonth').val();
		if(!startYear || startYear == '' || !startMonth || startMonth == '') {
			if($('#loanMonth').val() == '36') {
				$('#loanMonth').val('12');
			}
			 $('#loanMonth option[value="36"]').hide();
			 return;
		}
		var initMonth;
		var loanBank = $('#loanBank').val();
		if('ICBC' == loanBank){
			initMonth = 96;
		} else if('BOC' == loanBank){
			initMonth = 94;
		} else {
			if($('#loanMonth').val() == '36') {
				$('#loanMonth').val('12');
			}
			 $('#loanMonth option[value="36"]').hide();
			 return;
		}
		var now = new Date();
		var year = now.getFullYear();
		var month = now.getMonth() + 1;
		var nowMonth =(year - startYear) * 12 + (month - startMonth);
		if(initMonth - nowMonth >= 36) {
			 $('#loanMonth option[value="36"]').show();
		} else {
			if($('#loanMonth').val() == '36') {
				$('#loanMonth').val('12');
			}
			$('#loanMonth option[value="36"]').hide();
		}
	} else {
		//新车不做处理
		 $('#loanMonth option[value="36"]').show();
	} */
}

/**
 * 计算车龄+车贷月份
 */
function countContinuedMonths(){
	var carType = $('#carType').val();
	var loanMonth = $('#loanMonth').val();
	var carAge  = $('#carAge').val();
	var continuedMonths = 0;
	if(carType == '02') { //二手车
		continuedMonths = ((carAge && carAge != '') ? parseInt(carAge) : 0) + ((loanMonth && loanMonth != '') ? parseInt(loanMonth) : 0);
	}
	return continuedMonths;
}

/**
 * 显隐提示信息
 */
function continuedMonthsWarning() {
	if($("#carType").val() == '02') {
		var continuedMonths = countContinuedMonths();
		if(continuedMonths >= 97) {
			$('#continuedMonthsWarning').show();
		} else {
			$('#continuedMonthsWarning').hide();
		}
	} else {
		$('#continuedMonthsWarning').hide();
	}
	
	var bankRate = $('#fast_bankRate').val();
	initBankRate(bankRate, function(bankRate){
		$('#bankRate').val(bankRate);
	});
}


//控制预警提示
function warning(){
    var loanBank = $('#loanBank').val();
    var carType = $('#carType').val();
    var zhkcj = $('#zhkcj').val();
    var qyhkcj = $('#qyhkcj').val();
    
	if(loanBank == 'ICBC') {
	    if(carType == '02') {
	    	showWarningUsedIcbc();
	    	if(zhkcj > 80) { //总还款/车价
	    		$('#zhkcj_show').show();
	    	} else {
	    		$('#zhkcj_show').hide();
	    	}
	    	if(qyhkcj > 70) { //签约贷款额/车价
	    		$('#qyhkcj_show').show();
	    	} else {
	    		$('#qyhkcj_show').hide();
	    	}
	    } else {
	    	showWarningNewIcbc();
	    	if(zhkcj > 90) {
	    		$('#zhkcj_show').show();
	    	} else {
	    		$('#zhkcj_show').hide();
	    	}
	    	if(qyhkcj > 80) {
	    		$('#qyhkcj_show').show();
	    	} else {
	    		$('#qyhkcj_show').hide();
	    	}
	    }
	} else if(loanBank == 'BOC') {
		   showWarningUsedBoc();
	    	if(zhkcj > 70) { //总还款/车价
	    		$('#zhkcj_show').show();
	    	} else {
	    		$('#zhkcj_show').hide();
	    	}
	    	if(qyhkcj > 70) { //签约贷款额/车价
	    		$('#qyhkcj_show').show();
	    	} else {
	    		$('#qyhkcj_show').hide();
	    	}
	}
}
</script>